package com.edu.servlet;



import com.edu.service.AdminNewsService;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/news/*")
public class AdminNewsServlet extends HttpServlet {  private AdminNewsService adminNewsService = new AdminNewsService();
    private static final String UPLOAD_DIRECTORY = "upload/news";
    private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String pathInfo = request.getPathInfo();
        if (pathInfo == null) {
            pathInfo = "/";
        }

        switch (pathInfo) {
            case "/list":
                listNews(request, response);
                break;
            case "/get":
                getNews(request, response);
                break;
            case "/comments":
                adminNewsService.getNewsComments(request, response);
                break;
            default:
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }

    private void getNews(HttpServletRequest request, HttpServletResponse response) {
    }

    private void listNews(HttpServletRequest request, HttpServletResponse response) {
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String pathInfo = request.getPathInfo();
        if (pathInfo == null) {
            pathInfo = "/";
        }

        switch (pathInfo) {
            case "/add":
                addNews(request, response);
                break;
            case "/update":
                updateNews(request, response);
                break;
            case "/delete":

        }
    }

    private void updateNews(HttpServletRequest request, HttpServletResponse response) {
    }

    private void addNews(HttpServletRequest request, HttpServletResponse response) {
    }
}